﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ASPNETPerformance.App_BusinessLogic.BasePages;
using ASPNETPerformance.App_BusinessLogic.Helpers;
using ASPNETPerformance.App_BusinessLogic.StaticPage;
using ASPNETPerformance.App_BusinessLogic.Utils;

namespace ASPNETPerformance._05_StaticPage {
    public partial class GenerationAll : BasePage {
        protected void Page_Load( object sender, EventArgs e )
        {
        }

        //http://www.yintai.com/product/productdetail.aspx?itemcode=07-015-000AC
        protected void BtnSave_Click( object sender, EventArgs e ) {
            string html = StaticPageManager.GetGenerationTemplateHTML();

            string categoryBreadCrumbsResult =
                ViewManager.RenderView( "~/UserControls/YinTaiModel1.ascx", StaticPageManager.GetGenerationCategoryBreadCrumbsData() );
            string productImagesResult =
                ViewManager.RenderView( "~/UserControls/YinTaiModel2.ascx", StaticPageManager.GetGenerationProductImagesData() );
            string productInfoResult =
                ViewManager.RenderView( "~/UserControls/YinTaiModel3.ascx",
                    StaticPageManager.GetGenerationProductsData().Find( f => f.ItemCode == "07-015-000AC" ) );

            var o = new {
                ItemCode = "07-015-000AC",
                CategoryBreadCrumbs = categoryBreadCrumbsResult,
                ProductImages = productImagesResult,
                ProductInfo = productInfoResult
            };

            string path = Server.MapPath( string.Format( "~/Temp/{0}.html", "07-015-000AC" ) );
            StaticPageManager.SaveGenerationStaticPage( path, html.HenriFormat( o ) );

            this.lblResult.Text = "生成成功。";
            this.HyperLink1.NavigateUrl = CommonHelper.GetDemosLocation() + "Temp/07-015-000AC.html";
        }

    }
}